JSTL (JSP Standard Tag Libary)

일반적인 웹 어플리케이션 기능(반복과 조건, 데이타 관리 포맷, XML 조작, 데이타베이스 액세스)을 구현하는 커스텀 태그 라이브러리 모음.

1. JSTL 현황

JSP2.0 스팩에 포함 (Tomcat 5.0(정식 버전)에 구현)

2. JSTL 처리영역

application, session, request, response, pageContext 등의 내장객체에 쉽게 접근.
파라메터, 헤더, 쿠기 등을 복잡한 코드를 사용하지 않고 직관적으로 사용.
기본적인 연산이나 객체 비교 등을 쉽게 구현, 조건, 반복, 이동에 대한 태그 지원
기본기능(core), 형식화(format), xml 처리(xml), sql 처리(sql)

기능prefix기본URL
기본기능chttp://java.sun.com/jstl/core
XML 처리xhttp://java.sun.com/jstl/xml
i18n & 형식화fmthttp://java.sun.com/jstl/fmt
데이터베이스 작업sqlhttp://java.sun.com/jstl/sql

3. JSTL 설치

tomcat5.0(정식버전)을 다운로드 하여 설치

1. EL(Expression Language)

1.1 표시형식

${}으로 내장객체 접근 가능하며, 산술연산과 비교연산 가능
dot(.)과 bracket([]) 모두를 이용하여 객체 내부의 자원에 접근 가능

1.2 내장객체

pageScopepage scope 의 변수들
requestScoperequest scope 의 변수들
sessionScopesession scope 의 변수들
applicationScopeapplication scope 의 변수들
paramparameter 변수들 문자열
paramValuesparameter 변수들 문자열 배열
headerHTTP request 헤더
headerValuesHTTP request 헤더 문자열 배열
initParam컨텍스트 초기 변수 web.xml 에서 지정
cookie쿠키 변수들
pageContext현재 페이지의 pageContext 객체

1.3 연산자

연산자 구분연산자
관계< (lt) > (gt) <= (le) >= (ge) == (eq) != (ne)
산술+ - * / (div) % (mod)
논리&& (and) ㅣㅣ (or) ! (not)
Emptyempty

1.4 예제


<% response.setContentType("text/html;"); %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<c:if test="${!empty hit}">
    <c:set var="hit" value="${hit+1}" scope="session"/>
    <c:out value="${hit}"/> 번 리로드되었습니다.
</c:if>

<c:if test="${empty hit}">
    <c:set var="hit" value="1" scope="session"/>
    세션에 값을 저장했습니다.
</c:if>
<br>
<a href="jstlel03.jsp">reload</a>

null인지 판단하여 세션값이 없으면, 값을 지정하고 있으면 하나를 더한 후에 출력하는 코드

2. Core Tag

3. Format Tag

4. SQL Tag

5. XML Tag

문서에 대하여